package org.wzy.spring.deprecated.mvc.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wzy.spring.deprecated.manually.annotation.Autowired;
import org.wzy.spring.deprecated.manually.annotation.Controller;
import org.wzy.spring.deprecated.manually.annotation.RequestMapping;
import org.wzy.spring.deprecated.manually.annotation.RequestParam;
import org.wzy.spring.deprecated.mvc.demo.service.IDemoService;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * DemoController1, 测试 IOC 容器是否初始化成功, 所有的依赖是否全部注入成功
 *
 * @author wzy_h
 * @version v_1.0
 * @date 2018/5/19 16:31
 * @since 1.8
 */
@Deprecated
@Controller("/demo1")
public class DemoController1 {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IDemoService demoService;

    @RequestMapping("/get")
    public void getSth(HttpServletResponse response, @RequestParam("name") String name) {
        String result = demoService.get(name);
        try {
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void test(String name) {
        String result = demoService.get(name);
        logger.error("打印 DemoController1 中的 IDemoService 对象所在的内存地址={}, result={}", demoService, result);
    }
}
